home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11300 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: risky.ecs.umass.edu!usenet
  2. From: jvinson@cheux.ecs.umass.edu (Jack Vinson)
  3. Newsgroups: comp.lang.c++
  4. Subject: template instantiation (was passing references to containers?)
  5. Date: 13 Mar 1996 15:13:31 -0500
  6. Organization: University of Massachusetts
  7. Message-ID: <wopwaglpjo.fsf_-_@cheux.ecs.umass.edu>
  8. References: <wozq9lc29c.fsf@cheux.ecs.umass.edu>
  9. NNTP-Posting-Host: cheux.ecs.umass.edu
  10. To: jvinson@cheux.ecs.umass.edu (Jack Vinson)
  11. X-Newsreader: September Gnus v0.51/Emacs 19.30
  12.  
  13. >>>>> "JV" == Jack Vinson <jvinson@cheux.ecs.umass.edu> writes:
  14.  
  15. JV> I have a basic array template that does bound-checking in the [] operator.
  16. JV> I want to pass these arrays around by reference to reduce the amount of
  17. JV> creating and destroying going on.  
  18.  
  19. JV> However, in SOME cases, the compiler complains when I try to access
  20. JV> elements of the given array... [snip]
  21.  
  22. I found the error.  This has to do with the fact that a template needs to
  23. be instantiated in each file where it is used.  In general this doesn't
  24. bite people, but when I want to pass my container around it may not get
  25. instantiated elsewhere in the file.
  26.  
  27. From reading this group, it appears that the solutions is to add a dummy
  28. function to each file (or to a common .h file) with variables of the
  29. appropriate types.
  30.  
  31. i.e. 
  32.  
  33. void foo()
  34. {
  35.   array<class1> c1;
  36.   array<class2> c2;
  37. }
  38.  
  39. will create array templates for class1 and class2 so they can be used in
  40. the code in the given file.
  41.  
  42. Where can I read up on the rationale for this.
  43.  
  44. -- 
  45. Jack Vinson                       jvinson@cheux.ecs.umass.edu
  46. "I Spit on Your Grave"            -- double feature at the drive-in as seen
  47. "I Thumb Through Your Magazines"     from the Qwik-E mart
  48.  
  49.